<?php
namespace  Admin\Controller;
use Utuo\BackgroundController;
class NodeController extends BackgroundController
{   
	private  $status=array(
			'1'=>'开启',
			'0'=>'关闭'	
	);
	
	public  function _initialize(){
		$this->setControllerTitle('节点管理');
		$this->setActionTitle(array(
				'index' => '节点列表',
				'add' => '添加节点',
				'modify' => '修改节点',
				'recycle' => '回收站',
				
		), "", "pid={$_GET['pid']}&level={$_GET['level']}");
		$this->setActionNav(array(
				'index',
				'add',
				'recycle'
		));
	}
	public function getLists($is_deleted)
	{   $condation=array(
		'is_deleted'=>$is_deleted	
	);
	    $field=array('id,name,pid,level,remark');
	   	$nodes=M('Node')->where($condation)->field($field)->select();
	   	$nodes=makeListLevel($nodes,0,'pid');
	   
	    $this->assign('data',$nodes)->display();
		
	}
	public function addAction(){
	$node['pid']=I('pid',0,'intval');
	$node['level']=I('level',1,'intval');	
	switch ($node['level'])
	{
		case 1:
			$node['app_name']="应用";
		       break;
	    case 2:
		    $node['app_name']="控制器";
		       	break;
	    case 3:
		     $node['app_name']="动作方法";
		       		break;
	}
	
	$sort=M('node')->max('sort');
	$node['radio']=\Utuo\Form::getRadio("status", $this->status,1);
	$node['sort']=$sort+1;

    $this->assign('data',$node);
	$this->display('save');
	}
	public function modifyAction($id)
	{
		$node=M('node')->getById($id);
		$node['radio']=\Utuo\Form::getRadio("status", $this->status,$node['status']);
		
		$this->assign('data',$node);
		$this->display('save');
	}
}